﻿/*
--------------------------------------
File: Batch.cs
Project: Themaopdracht 7
Author: Maarten Kroon & Thierry Gerritse

Description:
A batch that can perform several vision algoritms in a row
--------------------------------------
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace THO7_Team8
{
    public class Batch : VisionAlgorithm
    {
        public Batch(String name)
            : base(name)
        {
        }
        public override Bitmap DoAlgorithm(Bitmap sourceImage)
        {
            //SimpleColorDetect checks for yellowpixels in the image
            SimpleColorDetectMonogrome simpleColorDetectMonochrome = new SimpleColorDetectMonogrome("");
            Bitmap simpleColorDetectMonochromeResult1 = simpleColorDetectMonochrome.DoAlgorithm(sourceImage);

            //BlobDetection to filter small blobs, multiple blobs and blobs which do not have the right dimensions
            LicensePlateBlobDetection licensePlateBlobDetection = new LicensePlateBlobDetection("");
            Bitmap licensePlateBlobDetectionResult = licensePlateBlobDetection.DoAlgorithm(simpleColorDetectMonochromeResult1);

            //Crop license plate and returns the original colors
            //This is needed to return the small black spaces in letters
            CropLicenseplateColoured cropLicensePlateColored = new CropLicenseplateColoured("");
            Bitmap cropLicensePlateColoredResult = cropLicensePlateColored.CropLicensePlateFromOriginal(licensePlateBlobDetectionResult, sourceImage);

            //Make monochrome, needed for cropEdges
            MakeMonochrome makeMonochrome = new MakeMonochrome("");
            Bitmap makeMonochromeResult = makeMonochrome.DoAlgorithm(cropLicensePlateColoredResult);

            //Rotate the license plate
            //We do not use this at the moment, it makes the result often worse
            //RotateLicensePlate rotateLicensePlate = new RotateLicensePlate("");
            //Bitmap rotateLicensePlateResult = rotateLicensePlate.DoAlgorithm(makeMonochromeResult);

            //Crops the black edges around the license plate, also filters noise
            CropEdges cropEdges = new CropEdges("");
            Bitmap cropEdgesResult = cropEdges.DoAlgorithm(makeMonochromeResult);

            if (cropEdgesResult != null)
            {
                return cropEdgesResult;
            }
            else
            {
                //MessageBox.Show("Geen bruikbaar resultaat gevonden");
                return null;
            }
        }
    }
}
